import java.util.HashMap;

/**
* @description: 447. 回旋镖的数量
* @author hewei
* @date 2022/8/4 14:54
* @version 1.0
*/

public class NumberOfBoomerangs {

    public int numberOfBoomerangs(int[][] points) {
        int ans = 0;
        for (int i = 0; i < points.length; i++) {
            HashMap<Integer, Integer> map = new HashMap<>();
            for (int j = 0; j < points.length; j++) {
                if (j == i) continue;
                int sum = (points[i][0] - points[j][0]) * (points[i][0] - points[j][0])
                        + (points[i][1] - points[j][1]) * (points[i][1] - points[j][1]);
                map.put(sum, map.getOrDefault(sum, 0) + 1);
            }
            for (Integer value : map.values()) {
                if (value >= 2) ans += value * (value - 1);
            }
        }
        return ans;
    }
}
